package com.tanhua.server.controller;

import com.tanhua.domain.db.PageResult;
import com.tanhua.domain.vo.CommentVo;
import com.tanhua.server.service.LinkedCommentService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.ObjectInput;
import java.util.Map;

@RestController
@RequestMapping("/smallVideos")
public class VideoLinkedCommentController {
    //共有linkedCommentService方法
    @Autowired
    private LinkedCommentService linkedCommentService;

    /**
     * 小视频评论列表
     */
    @GetMapping("/{id}/comments")
    public ResponseEntity videoLinkedCommentData(@PathVariable("id") String videoId,
                               @RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize) {
        //1.调用service层 传入分页条件和发布
        PageResult<CommentVo> pageResult= linkedCommentService.videoLinkedCommentData(1,videoId,page,pagesize);
        //2.返回状态信息
        return ResponseEntity.ok(pageResult);
    }


//    小视频提交自己的评论
    @PostMapping("/{id}/comments")
    public ResponseEntity submitVideoComments(@PathVariable("id") String videoId,@RequestBody Map map) {
        //1.调用service层 传入发布id和评论信息
        //评论内容
        String comment = (String) map.get("comment");
        linkedCommentService.submitVideoComments(videoId,comment);
        //2.返回状态信息
        return ResponseEntity.ok(null);
    }

    //  小视频评论-点赞
    @PostMapping("/{id}/comments/like")
    public ResponseEntity videoLinkedLikeStatus(@PathVariable("id")String commendId) {
        //1.调用service层 传入分页条件和发布
        long linkedLikeCount=linkedCommentService.getVideoLinkedLikeCount(commendId);
        //2.返回状态信息
        return ResponseEntity.ok(linkedLikeCount);
    }
    //  小视频评论-取消点赞
    @PostMapping("/{id}/comments/dislike")
    public ResponseEntity disVideoLinkedLikeStatus(@PathVariable("id")String commentId) {
        //1.调用service层 传入分页条件和发布
        long linkedLikeCount=linkedCommentService.getDisVideoLinkedLikeStatus(commentId);
        //2.返回状态信息
        return ResponseEntity.ok(linkedLikeCount);
    }

}
